package com.example.democrud.employee;

import com.example.democrud.ResponseVO;
import com.example.democrud.employee.dao.EmployeeMapper;
import com.example.democrud.employee.pojo.EmployeeDO;
import com.example.democrud.employee.pojo.EmployeeDTO;
import com.example.democrud.employee.pojo.EmployeeVO;
import com.example.democrud.group.Insert;
import com.example.democrud.group.Update;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javafx.beans.binding.When;
import jdk.nashorn.internal.objects.annotations.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.GroupSequence;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @ClassName EmployeeController
 * @Author Administrator
 * @Date 2020/4/22   13:48
 */
@Api(value = "EmployeeController",tags = "员工模块")
@RestController
@RequestMapping(value = "/employee" )
@Validated
@Slf4j
public class EmployeeController {
    private final EmployeeService employeeService;

    public EmployeeController(EmployeeService employeeService){
        this.employeeService = employeeService;
    }


    /*{@RequestBody默认用 HttpMessageConverter转换}*/
    @ApiOperation("添加员工")
    @PostMapping(value = "/create",consumes = MediaType.APPLICATION_JSON_VALUE , produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO<String> create(@RequestBody @Validated(Insert.class) EmployeeDTO employeeDTO){
        return ResponseVO.successData(String.valueOf(employeeService.create(employeeDTO)));
    }

    @ApiOperation("员工信息修改")
    @PutMapping(value = "/update" ,consumes = MediaType.APPLICATION_JSON_VALUE,produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO<String> update(@RequestBody @Validated(Update.class) EmployeeDTO employeeDTO ){

        return ResponseVO.successData(String.valueOf(employeeService.update(employeeDTO)));
    }

    @ApiOperation("员工检索信息")
    @GetMapping(value = "/retrieve/{employeeId}" ,produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO<EmployeeVO> retrieve(@PathVariable(value = "employeeId") @NotNull @Valid Long id){

        return ResponseVO.successData(employeeService.retrieve(id));
    }

    @ApiOperation("所有员工检索信息")
    @GetMapping(value = "/retrieve" ,produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO<List<EmployeeVO>> retrieve(){
        return ResponseVO.successData(employeeService.retrieve());
    }

}
